//modifyphone.js
let timer;
Page({
  data: {
    transparent: 0.3,
    oldphone: '',
    newphone: '',
    verifcode: '',
    getCode: '获取验证码',
    noUse:false
  },
  onLoad: function () {
    
  },
  modifyOldPhone: function (e) {
    let that = this;
    let old = e.detail.value;
    if(old.length == 11){
      let telStr = /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/;
      if (!(telStr.test(old))) {
        wx.showToast({
          title: '请输入有效的手机号',
          icon: 'none',
          duration: 1500
        })
      } else {
        that.setData({oldphone:old})
      }
      if (that.data.newphone.length == 11 && that.data.verifcode != '') {
          that.setData({transparent:1})
      }
    } else {
      that.setData({transparent:0.3})
    }
  },
  modifyNewPhone: function (e) {
      let that = this;
      let news = e.detail.value;
      if(news.length == 11){
        let telStr = /^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$/;
        if (!(telStr.test(news))) {
          wx.showToast({
            title: '请输入有效的手机号',
            icon: 'none',
            duration: 1500
          })
        } else {
          that.setData({newphone:news})
        }
        if (that.data.oldphone.length == 11 && that.data.verifcode != '') {
          that.setData({transparent:1})
        }
      } else {
        that.setData({transparent:0.3})
      }
  },
  modifyVerifCode: function (e) {
    let that = this;
    let Verif = e.detail.value;
    if (Verif != '') {
      that.setData({ verifcode: Verif })
      if (that.data.oldphone.length == 11 && that.data.newphone.length == 11) {
          that.setData({transparent:1})
      }
    } else {
      that.setData({transparent:0.3})
    }
  },
  getCode: function () {
    let that = this;
    let time = 61;
    let newNum = that.data.newphone;
    if (newNum != '') {
      timer = setInterval(function(){
         time--;
         if(time==-1){
             clearInterval(timer);
             that.setData({
               getCode: '获取验证码',
               noUse:false
             })
         }else{
             that.setData({
               getCode: time + 'S',
               noUse:true
            })
         }            
       },1000)
    }
  }
})
